package com.cssnj.portal.web.user;

import com.cssnj.portal.service.user.ExplainService;
import io.predictech.framework.domain.common.JsonRequest;
import io.predictech.framework.domain.common.JsonResponse;
import io.predictech.framework.domain.exception.BaseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping({"/user/explain"})
public class ExplainController {

    @Autowired
    private ExplainService explainService;

    @RequestMapping({"/init.do"})
    public ModelAndView init(HttpServletRequest request) throws BaseException, SQLException {
        //页面初始化
        String gnid = request.getParameter("gnid");
        JsonRequest jsonRequest = new JsonRequest();
        jsonRequest.setServiceName("explainService");
        jsonRequest.setHandleCode("init");
        jsonRequest.getReqData().put("gnid", gnid);
        JsonResponse jsonResponse = explainService.execute(jsonRequest);
        String gnmc = (String) jsonResponse.getRepData().get("gnmc");
        String gnms = (String) jsonResponse.getRepData().get("gnms");
        String xqsm = (String) jsonResponse.getRepData().get("xqsm");
        String jssm = (String) jsonResponse.getRepData().get("jssm");
        String yymc = (String) jsonResponse.getRepData().get("yymc");
        List<Map<String, Object>> jsList = (List<Map<String, Object>>) jsonResponse.getRepData().get("jsList");
        List<Map<String, Object>> xqList = (List<Map<String, Object>>) jsonResponse.getRepData().get("xqList");
        ModelAndView modelAndView = new ModelAndView("user/explain");
        modelAndView.getModelMap().put("gnmc", gnmc);
        modelAndView.getModelMap().put("gnms", gnms);
        modelAndView.getModelMap().put("xqsm", xqsm);
        modelAndView.getModelMap().put("jssm", jssm);
        modelAndView.getModelMap().put("yymc", yymc);
        modelAndView.getModelMap().put("jsList", jsList);
        modelAndView.getModelMap().put("xqList", xqList);
        return modelAndView;
    }
}
